﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MemberManager_AddMember : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            RECORDID.Text = "";
            String rID = Page.Request["ID"];
            if (rID != null && rID != "")
            {
                EntityOprHelper helper = new EntityOprHelper();
                T_USER add = helper.GetEntityByWhere<T_USER>(" where ID=" + rID + "");
                if (add != null)
                {
                    RECORDID.Text = add.ID.ToString();
                    pName.Text = add.NAME;
                    pQQ.Text = add.QQ;
                    pMSN.Text = add.MSN;
                    pEmail.Text = add.EMAIL;
                    pTel.Text = add.TEL;
                    pAddress.Text = add.ADDRESS;
                    pPassword.Text = add.PASSWORD;
                }
            }

        }
    }
    protected void Submit_Click(object sender, EventArgs e)
    {
        if (pName.Text == ""||pPassword.Text=="")
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('请输入用户名称和密码')", true);
            return;
        }
        EntityOprHelper helper = new EntityOprHelper();
        if (RECORDID.Text != "")
        {
            T_USER address = new T_USER();
            address.ID = Convert.ToInt32(RECORDID.Text);

            address.NAME = pName.Text;
            address.PASSWORD = pPassword.Text;
            address.QQ = pQQ.Text;
            address.MSN = pMSN.Text;
            address.EMAIL = pEmail.Text;
            address.TEL = pTel.Text;
            address.ADDRESS = pAddress.Text;


            bool b1 = helper.EditEntity<T_USER>(address);
            if (b1)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改成功')", true);
                pName.Text = "";
                pQQ.Text = "";
                pMSN.Text = "";
                pEmail.Text = "";
                pTel.Text = "";
                pAddress.Text = "";
                RECORDID.Text = "";
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改失败')", true);
            }

            return;
        }



        T_USER add = helper.GetEntityByWhere<T_USER>(" where NAME='" + pName.Text + "'");

        if (add != null)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('该用户已经存在')", true);
            return;
        }

        T_USER _address = new T_USER();
        _address.NAME = pName.Text;
        _address.PASSWORD = pPassword.Text;
        _address.QQ = pQQ.Text;
        _address.MSN = pMSN.Text;
        _address.EMAIL = pEmail.Text;
        _address.TEL = pTel.Text;
        _address.ADDRESS = pAddress.Text;
        bool b = helper.AddEntity<T_USER>(_address);
        if (b)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('添加成功')", true);
            pName.Text = "";
            pQQ.Text = "";
            pMSN.Text = "";
            pEmail.Text = "";
            pTel.Text = "";
            pAddress.Text = "";

        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('添加失败')", true);
        }



    }
}
